package siyuan.run.nacos.security.oauth2.mysql.service;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import siyuan.run.nacos.security.oauth2.mysql.repository.UserRepository;
import siyuan.run.nacos.security.oauth2.mysql.model.User;

/**
 * @program: sy
 * @description:
 * @author: SY
 * @create: 2020-12-20 21:59
 **/
public class UserSecurityService implements UserDetailsService {
    @Autowired
    private UserRepository userRepository;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userRepository.findByUsername(username);
        if (ObjectUtil.isEmpty(user)){
            throw new UsernameNotFoundException("用户不存在");
        }
        return user;
    }
}
